drsxobip501258 2016-08-24 08:41
浏览 57

使用codeigniter中的doDirect方法进行Paypal重复付款

Hello I created a PHP script which is able to create recurring profile in Paypal but arising some quations

-> What should I call first Paypal recurring profile method or Paypal do direct method because I need to deduct payment every day.

-> What should be notify url if in future customer card would be expired or happen something or in I am not getting payment as per cycles.

Below I mentioned my code which I used to create Paypal recurring profile

`   function Do_direct_payment()
{

    $DPFields = array(
                    'paymentaction' => $this->input->post('paymentType'),                       // How you want to obtain payment.  Authorization indidicates the payment is a basic auth subject to settlement with Auth & Capture.  Sale indicates that this is a final sale for which you are requesting payment.  Default is Sale.
                    'ipaddress' => $_SERVER['REMOTE_ADDR'],                             // Required.  IP address of the payer's browser.
                    'returnfmfdetails' => '1'                   // Flag to determine whether you want the results returned by FMF.  1 or 0.  Default is 0.
                    );


    $ProfileDetails = array(
            'subscribername' => 'shakti',                   // Full name of the person receiving the product or service paid for by the recurring payment.  32 char max.
            'profilestartdate' => '2016-08-24T18:29:50.588Z',
            'profileenddate' => '2016-08-26T18:29:50.588Z',                     // Required.  The date when the billing for this profile begins.  Must be a valid date in UTC/GMT format.
            'profilereference' => ''                    // The merchant's own unique invoice number or reference ID.  127 char max.
    );

    $ScheduleDetails = array(
            'desc' => 'this is first recurring payment for testing',                                // Required.  Description of the recurring payment.  This field must match the corresponding billing agreement description included in SetExpressCheckout.
            'maxfailedpayments' => '',                  // The number of scheduled payment periods that can fail before the profile is automatically suspended.
            'autobilloutamt' => ''                      // This field indicates whether you would like PayPal to automatically bill the outstanding balance amount in the next billing cycle.  Values can be: NoAutoBill or AddToNextBilling
    );

    $BillingPeriod = array(
            'trialbillingperiod' => '',
            'trialbillingfrequency' => '',
            'trialtotalbillingcycles' => '',
            'trialamt' => '100',
            'billingperiod' => 'Day',                       // Required.  Unit for billing during this subscription period.  One of the following: Day, Week, SemiMonth, Month, Year
            'billingfrequency' => '1',                  // Required.  Number of billing periods that make up one billing cycle.  The combination of billing freq. and billing period must be less than or equal to one year.
            'totalbillingcycles' => '3',                // the number of billing cycles for the payment period (regular or trial).  For trial period it must be greater than 0.  For regular payments 0 means indefinite...until canceled.
            'amt' => '1000',                                // Required.  Billing amount for each billing cycle during the payment period.  This does not include shipping and tax.
            'currencycode' => 'USD',                        // Required.  Three-letter currency code.
            'shippingamt' => '',                        // Shipping amount for each billing cycle during the payment period.
            'taxamt' => ''                              // Tax amount for each billing cycle during the payment period.
    );

    $ActivationDetails = array(
            'initamt' => '',                            // Initial non-recurring payment amount due immediatly upon profile creation.  Use an initial amount for enrolment or set-up fees.
            'failedinitamtaction' => '',                // By default, PayPal will suspend the pending profile in the event that the initial payment fails.  You can override this.  Values are: ContinueOnFailure or CancelOnFailure
    );

    $CCDetails = array(

                        'creditcardtype' => $this->input->post('creditCardType'),                   // Required. Type of credit card.  Visa, MasterCard, Discover, Amex, Maestro, Solo.  If Maestro or Solo, the currency code must be GBP.  In addition, either start date or issue number must be specified.
                        'acct' => $this->input->post('creditCardNumber'),                               // Required.  Credit card number.  No spaces or punctuation.  
                        'expdate' => $this->input->post('expDateMonth').$this->input->post('expDateYear'),                          // Required.  Credit card expiration date.  Format is MMYYYY
                        'cvv2' => $this->input->post('cvv2Number'),                                 // Requirements determined by your PayPal account settings.  Security digits for credit card.
                        'startdate' => '',                          // Month and year that Maestro or Solo card was issued.  MMYYYY
                        'issuenumber' => ''                         // Issue number of Maestro or Solo card.  Two numeric digits max.
                    );

    $PayerInfo = array(
                        'email' => $this->input->post('email'),                                 // Email address of payer.
                        'payerid' => '',                            // Unique PayPal customer ID for payer.
                        'payerstatus' => '',                        // Status of payer.  Values are verified or unverified
                        'business' => 'Testers, LLC'                            // Payer's business name.
                    );

    $PayerName = array(
                        'salutation' => 'Mr.',                      // Payer's salutation.  20 char max.
                        'firstname' => $this->input->post('firstName'),                             // Payer's first name.  25 char max.
                        'middlename' =>$this->input->post('lastName'),                      // Payer's middle name.  25 char max.
                        'lastname' => $this->input->post('lastName'),                           // Payer's last name.  25 char max.
                        'suffix' => ''                              // Payer's suffix.  12 char max.
                    );

    $BillingAddress = array(
                            'street' => '123 Test Ave.',                        // Required.  First street address.
                            'street2' => '',                        // Second street address.
                            'city' => $this->input->post('city'),                           // Required.  Name of City.
                            'state' => $this->input->post('state'),                             // Required. Name of State or Province.
                            'countrycode' => $this->input->post('country'),                     // Required.  Country code.
                            'zip' => $this->input->post('zip'),                             // Required.  Postal code of payer.
                            'phonenum' => $this->input->post('phone')                       // Phone Number of payer.  20 char max.
                        );

    $ShippingAddress = array(
                            'shiptoname' => 'Tester Testerson',                     // Required if shipping is included.  Person's name associated with this address.  32 char max.
                            'shiptostreet' => '123 Test Ave.',                  // Required if shipping is included.  First street address.  100 char max.
                            'shiptostreet2' => '',                  // Second street address.  100 char max.
                            'shiptocity' => 'Kansas City',                  // Required if shipping is included.  Name of city.  40 char max.
                            'shiptostate' => 'MO',                  // Required if shipping is included.  Name of state or province.  40 char max.
                            'shiptozip' => '64111',                         // Required if shipping is included.  Postal code of shipping address.  20 char max.
                            'shiptocountry' => 'US',                    // Required if shipping is included.  Country code of shipping address.  2 char max.
                            'shiptophonenum' => '555-555-5555'                  // Phone number for shipping address.  20 char max.
                            );

    $PaymentDetails = array(
                            'amt' => $this->input->post('amount') ,                             // Required.  Total amount of order, including shipping, handling, and tax.  
                            'currencycode' => 'USD',                    // Required.  Three-letter currency code.  Default is USD.
                            'itemamt' => '95.00',                       // Required if you include itemized cart details. (L_AMTn, etc.)  Subtotal of items not including S&H, or tax.
                            'shippingamt' => '5.00',                    // Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
                            'shipdiscamt' => '',                    // Shipping discount for the order, specified as a negative number.  
                            'handlingamt' => '',                    // Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
                            'taxamt' => '',                         // Required if you specify itemized cart tax details. Sum of tax for all items on the order.  Total sales tax. 
                            'desc' => 'Web Order',                          // Description of the order the customer is purchasing.  127 char max.
                            'custom' => '',                         // Free-form field for your own use.  256 char max.
                            'invnum' => '',                         // Your own invoice or tracking number
                            'notifyurl' => $this->input->post('notifyURL')                      // URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
                        );  

    $OrderItems = array();
    $Item    = array(
                        'l_name' => 'Test Widget 123',                      // Item Name.  127 char max.
                        'l_desc' => 'The best test widget on the planet!',                      // Item description.  127 char max.
                        'l_amt' => '95.00',                             // Cost of individual item.
                        'l_number' => '123',                        // Item Number.  127 char max.
                        'l_qty' => '1',                             // Item quantity.  Must be any positive integer.  
                        'l_taxamt' => '',                       // Item's sales tax amount.
                        'l_ebayitemnumber' => '',               // eBay auction number of item.
                        'l_ebayitemauctiontxnid' => '',         // eBay transaction ID of purchased item.
                        'l_ebayitemorderid' => ''               // eBay order ID for the item.
                );

    array_push($OrderItems, $Item);
    $Secure3D = array(
                      'authstatus3d' => '', 
                      'mpivendor3ds' => '', 
                      'cavv' => '', 
                      'eci3ds' => '', 
                      'xid' => ''
                      );

    $PayPalRequestData = array(
                            'DPFields' => $DPFields, 
                            'ProfileDetails' => $ProfileDetails,
                            'ScheduleDetails' => $ScheduleDetails,
                            'BillingPeriod' => $BillingPeriod,
                            'ActivationDetails' => $ActivationDetails,
                            'CCDetails' => $CCDetails, 
                            'PayerInfo' => $PayerInfo, 
                            'PayerName' => $PayerName, 
                            'BillingAddress' => $BillingAddress, 
                            'ShippingAddress' => $ShippingAddress, 
                            'PaymentDetails' => $PaymentDetails, 
                            'OrderItems' => $OrderItems, 
                            'Secure3D' => $Secure3D
                                );



    $PayPalResult = $this->paypal_pro->CreateRecurringPaymentsProfile($PayPalRequestData);




    /*$CRPPFields = array(
            'token' => '',                              // Token returned from PayPal SetExpressCheckout.  Can also use token returned from SetCustomerBillingAgreement.
            'softdescriptor' => '',                     // Information that is usually displayed in the account holder's statement.  23 char max.
            'softdescriptorcity' => '',                 // A unique phone number, emaili address or URL, which is displayed on the account holder's statement.
    );

    echo '<pre>'; print_r($profileCreate);
    die; */

    if(!$this->paypal_pro->APICallSuccessful($PayPalResult['ACK']))
    {


        $errors = array('Errors'=>$PayPalResult['ERRORS']);
        $this->load->view('paypal/samples/error',$errors);
    }
    else
    {
        // Successful call.  Load view or whatever you need to do here.
        $data = array('PayPalResult'=>$PayPalResult);
        $this->load->view('paypal/samples/do_direct_payment',$data);
    }
}

This code works fine for me I can create a recurring payment profile.When I run this script I got response ACK success

[PROFILEID] => I-1EF5JR4CKE8C
[PROFILESTATUS] => ActiveProfile
[TIMESTAMP] => 2016-08-24T07:07:06Z
[CORRELATIONID] => 13d41eec3fe72
[ACK] => Success
[VERSION] => 123.0
[BUILD] => 000000

and now I go to my Paypal account I can see a Paypal recurring account has been created. But the problem is that the amount 100$ did not received while profile created.

  • 写回答

1条回答 默认 最新

  • dsflxcfuw27742248 2016-08-24 09:03
    关注

    You would not typically combine DoDirectPayment and CreateRecurringPaymentsProfile.

    If you're using a credit card to create the profile then just use CreateRecurringPaymentsProfile. For the one-time charge you would use the $ActivationDetails['initamt'] which is already included, but not currently populated in your code.

    So just get rid of the DoDirectPayment portions of this, and leave nothing but CreateRecurringPaymentsProfile. Charge the $100 in the INITAMT parameter and you should be set.

    评论

报告相同问题?

悬赏问题

  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题