iyzico/iyzipay-php

Trying to subscribe. Get error: Müşterinin kartı olmalı

FrancescoMussi opened this issue · 7 comments

I am testing the API endpoints.

I have successfully created a customer:

$request = new \Iyzipay\Request\Subscription\SubscriptionCreateCustomerRequest();
$request->setLocale("tr");
$request->setConversationId("1234567789");
$customer = new \Iyzipay\Model\Customer();
$customer->setName("John");
$customer->setSurname("Doe");
$customer->setGsmNumber("+905555555555");
$customer->setEmail("johndoe@iyzicotest.com");
$customer->setIdentityNumber("11111111111");
$customer->setShippingContactName("John Doe");
$customer->setShippingCity("Istanbul");
$customer->setShippingCountry("Turkey");
$customer->setShippingAddress("Uskudar Burhaniye Mahallesi iyzico A.S");
$customer->setShippingZipCode("34660");
$customer->setBillingContactName("John Doe");
$customer->setBillingCity("Istanbul");
$customer->setBillingCountry("Turkey");
$customer->setBillingAddress("Uskudar Burhaniye Mahallesi iyzico A.S");
$customer->setBillingZipCode("34660");
$request->setCustomer($customer);

$result = \Iyzipay\Model\Subscription\SubscriptionCustomer::create($request,Config::options());

I have successfully created a card:

$request = new \Iyzipay\Request\CreateCardRequest();
$request->setLocale(\Iyzipay\Model\Locale::TR);
$request->setConversationId("1234567789");
$request->setCardUserKey("aaaaaaaa");

$cardInformation = new \Iyzipay\Model\CardInformation();
$cardInformation->setCardAlias("card alias");
$cardInformation->setCardHolderName("John Doe");
$cardInformation->setCardNumber("5528790000000008");
$cardInformation->setExpireMonth("12");
$cardInformation->setExpireYear("2030");
$request->setCard($cardInformation);

# make request
$card = \Iyzipay\Model\Card::create($request, Config::options());

And I get the cardUserKey in the response.

However when I try to subscribe the customer to a plan, I get the following error:

{"status":"failure","errorCode":"42205","errorMessage":"Ucs müşteri için aktif değil.","systemTime":1580224592946}

This is the code:

$request = new \Iyzipay\Request\Subscription\SubscriptionCreateWithCustomerRequest();
$request->setConversationId("1234567789");
$request->setLocale("tr");
$request->setPricingPlanReferenceCode("09543d2f-c5bb-4c40-8476-a67ab65eb614");
$request->setSubscriptionInitialStatus("ACTIVE");
$request->setCustomerReferenceCode("5ba7d928-181c-4120-9ba0-b395d95f1828");
$result = \Iyzipay\Model\Subscription\SubscriptionCreateWithCustomer::create($request,Config::options());

The question is:
How can I actually link the created card with the previously created user?

frkcn commented

Hi @FrancescoMussi,

You need to create a card for a customer using universal card storage for a subscription.
Universal card storage documentation

Default credit card storage doesn't work with a subscription. There is no sample for universal card storage creation, so personally, I would recommend for you use checkout form. It returns the checkout form as an Html in response.

Sorry @frkcn, but I really don't get how this part should work..

The html form I get in response has some issue, like some flickering. And I really would like to have control on my HTML and js, and just send data to the Iyzypay API.

Using iyzipay-laravel the subscription part was working very smoothly:

$user->addCreditCard([
    'alias'  => 'asd',
    'number' => '5526080000000006',
    'month'  => '01',
    'year'   => '2030',
    'holder' => 'Mehmet Aydın Bahadır'
]);
$user->subscribe(IyzipayLaravel::findPlan('premium-plan'));

It was that simple.
Can I ask if there would be any problem using iyzipay-laravel for subscription?
Besides the fact that the repo is no longer maintaned, the API should still work right?

Follow-up question: there is any plan to restart active development on the iyzipay-laravel?
That would be great. It was very nice package.

frkcn commented

@FrancescoMussi old iyzico-laravel package provides custom subscription with scheduled jobs. And there is no option for a new native iyzico subscription.

If you do not want to worry about recurring payments then use the new subscription. But it is only working with universal card storage and there is no scenario for your use case.

There is a sample for API usage here: https://github.com/iyzico/iyzipay-php/blob/master/samples/subscription-samples/create_subscription_api.php

Also, I am working on a new laravel package and I hope it will be released soon.

Okay I managed to get it working with the checkout form.
It was not ideal with our setup: Laravel + Vue.
In the end it was a hacky implementation.

Anyway thanks for replying.
If there will be soon a Laravel Package that would be great!

frkcn commented

Hi @FrancescoMussi ,

Finally i can tag iyzico laravel package for pre-release. If you want to test it: https://github.com/frkcn/kasiyer

Great! Thanks for the info @frkcn